from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from rest_framework.generics import *
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from rest_framework.mixins import *
from apps.meiduo_admin.serializers.permission import PermissionSerializer, ContentTypeSerializer
from apps.meiduo_admin.utils import PageNum


class PermissionModelViewSet(ModelViewSet):

    queryset = Permission.objects.order_by('id').all()

    serializer_class = PermissionSerializer

    pagination_class = PageNum


# 实现contenttype列表数据的获取,3种视图方式
#  第一种 一级视图写法APIView
# class ContentTypeAPIView(APIView):
#     def get(self, request):
#         cts = ContentType.objects.all()
#         serializer = ContentTypeSerializer(cts, many=True)
#         return Response(serializer.data)


#  第二种是二级视图GenericAPIView
# class ContentTypeAPIView(GenericAPIView, ListModelMixin):
#     queryset = ContentType.objects.all()
#     serializer_class = ContentTypeSerializer
#
#     def get(self, request):
#         return self.list(request)


#  第三种是三级视图实现ListAPIView
class ContentTypeAPIView(ListAPIView):
    queryset = ContentType.objects.all()

    serializer_class = ContentTypeSerializer
